package com.example.blackjack;

import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Typeface;
import android.graphics.Paint.Style;
import android.text.style.TypefaceSpan;
import android.util.DisplayMetrics;
import android.view.View;

public class Coins extends View{
	
	int widthCoin = 0;
	int heightCoin = 0;
	Bitmap[] coint = new Bitmap[] {
			BitmapFactory.decodeResource(getResources(), R.drawable.coin_1),
			BitmapFactory.decodeResource(getResources(), R.drawable.coin_5),
			BitmapFactory.decodeResource(getResources(), R.drawable.coin_10),
			BitmapFactory.decodeResource(getResources(), R.drawable.coin_20),
	};
	private int nCoinCordsX = 0;
	private int nCoinCordsY = 0;
	private int BetCoint = 0;
	private int WinCoint = 0;
	private int nDefaultMoney = 10000;
	private int nCordsMoneyX = 0;
	private int nCordsMoneyY = 0;
	private int nCordsBetX;
	private int nCordsBetY;
	private int nFontSize;

	
	Typeface  mFace;
	Paint paint;
	private int nCordsWinX;
	private int nCordsWinY;
	
	public Coins(Context context) {
		super(context);
				
		DisplayMetrics metrics = context.getResources().getDisplayMetrics();
		widthCoin = metrics.widthPixels;
		heightCoin = metrics.heightPixels;
		
		if (widthCoin == 480){
			nCoinCordsX = 80;
			nCoinCordsY = 650;
			
			nCordsMoneyX = 45;
			nCordsMoneyY = 45;
			
			nCordsBetX = 218;
			nCordsBetY = 45;
			
			nCordsWinX = 380;
			nCordsWinY = 45;
			
			nFontSize = 18;
		}
	
		
		mFace = Typeface.createFromAsset(getContext().getAssets(), "BodoniXT.ttf");
	
		paint = new Paint();
		paint.setColor(Color.WHITE);
		paint.setStyle(Style.STROKE);
		paint.setTextSize(nFontSize);
		paint.setTypeface(mFace);
		
	}
	
	
	
	public void DrawCoint(Canvas coin){
		
		for (int i = 0; i < coint.length; i++){
			coin.drawBitmap(coint[i], nCoinCordsX+coint[i].getWidth()*i, nCoinCordsY, paint);
		}
		
		String sMoney = String.valueOf(nDefaultMoney);
		coin.drawText(sMoney, nCordsMoneyX, nCordsMoneyY, paint);
		
		String sBet = String.valueOf(BetCoint);
		coin.drawText(sBet,nCordsBetX, nCordsBetY, paint);

		String sWin = String.valueOf(WinCoint);
		coin.drawText(sWin,nCordsWinX, nCordsWinY, paint);

	}
	
	public void ClickCoin(float nX, float nY){
		
		int Coin_W = coint[0].getWidth();
		int Coin_H = coint[0].getHeight();
		
		for (int i = 0; i < coint.length; i++){
			if (nX >= nCoinCordsX+Coin_W*i && nX < (nCoinCordsX+Coin_W*i + Coin_W)
					&& nY >= nCoinCordsY && nY < (nCoinCordsY + Coin_H)) {
	    		switch(i) {
	    		case 0:
	    			BetCoint+=1;
	    			nDefaultMoney -= 1;
	    			break;
	    		case 1:
	    			BetCoint+=5;
	    			nDefaultMoney -= 5;
	    			break;
	    		case 2:
	    			BetCoint+=10;
	    			nDefaultMoney -= 10;
	    			break;	    		
	    		case 3:
		    		BetCoint+=20;
		    		nDefaultMoney -= 20;
		    		break;
	    		}

			}
		}
		
	}
	
	
	public int GetBet(){
		return BetCoint;
	}
	
	public void ClearCoint(){
		//nDefaultMoney = 10000;
		BetCoint = 0;
	}
	

}
